package com.lagou.demo03.servlet;

import com.lagou.demo03.dao.StudentQueryDao;
import com.lagou.demo03.dao.StudentQueryDaoImp;
import com.lagou.demo03.model.Student;
import com.lagou.demo03.service.StudentQueryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "StudentQueryServlet")
public class StudentQueryServlet extends HttpServlet {
//    @Override
//    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        StudentQueryDao studentQueryDao = new StudentQueryDaoImp();
//        List<Map<String, Object>> list = studentQueryDao.studentQuery();
//        req.setAttribute("date",list);
//        //请求转发到某个jsp
//        req.getRequestDispatcher("student.jsp").forward(req,resp);
//    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        StudentQueryService studentQueryService = new StudentQueryService();
        List<Student> queryList = studentQueryService.studentItemService();
        request.setAttribute("list", queryList);
        request.getRequestDispatcher("student.jsp").forward(request, response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
